//
// Created by YueChuan on 2023/3/24.
//

#include "talkTextEdit.h"


talkTextEdit::talkTextEdit(QWidget *parent) : QTextEdit(parent) {
    this->setAcceptDrops(true);
}

void talkTextEdit::dropEvent(QDropEvent *event) {
    QString path = event->mimeData()->text().replace("file:///", "");
    this->setCursor(Qt::ArrowCursor);
    QFileInfo info(path);
    QString fileName = info.fileName();
    QFileIconProvider icon_provider;
    QIcon icon = icon_provider.icon(info);
    QPixmap image = icon.pixmap(64, 64);
    QImage image1 = image.toImage();
    QTextCursor cursor = this->textCursor();
    cursor.insertImage(image1);
    event->accept();
}

void talkTextEdit::dragEnterEvent(QDragEnterEvent *event) {
    this->setCursor(Qt::DragCopyCursor);
}

void talkTextEdit::dragLeaveEvent(QDragLeaveEvent *event) {
    this->setCursor(Qt::ArrowCursor);
}